<template>
  <div class="app-container">
    <el-form label-width="100px" width="200">
        <el-form-item label="类别名称">
          <el-input v-model="goodCate.goodsCateName"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateGoodCateInfo()">保存</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>

<script>
import goods_cate from '@/api/goods_cate';
export default {
  name:'GoodCateEdit',
  props:['id', 'goodsCateName'],
  data(){
    return {
        goodCate:{
          id:this.$props.id,
          goodsCateName:this.$props.goodsCateName
        }
    }
  },
  methods:{
    updateGoodCateInfo(){
      let goodCateDto = {
        id:this.goodCate.id,
        goodsCateName:this.goodCate.goodsCateName
      }
      console.log('待更新的数据goodCateDto：', goodCateDto)
      goods_cate.updateGoodCate(goodCateDto).then(
        response => {
            console.log('更新响应数据：', response)
            let resData = response.data.data
            let resCode = response.data.code
            let resMsg = response.data.message
            if(resCode == '200' && resData){
                //提示
                this.$message({
                    type: 'success',
                    message: '编辑成功!'
                })
                //跳转列表页面，使用路由跳转方式实现
                this.$router.push({path:'/good_cate_list'})
            } else {
                //异常提示
                this.$message({
                    type: 'error',
                    message: resMsg
                })
            }
        },
        error => {
            console.error('商品种类更新异常信息：', error)
        }
      )
    }
  }
}
</script>

<style scoped>
  .el-input{
    width: 223px;
  }
</style>